<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="billNo" slot-scope="text, record" @click="handleDetail(record)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

      </a-table>
    </div>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'

export default {
  name: 'ErpHrTrainingApplyRecordList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
  },
  props: {
    disabledButton: {
      type: Boolean,
      default: false
    },
    finalId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      description: '培训申请记录页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'billNo',
          scopedSlots: { customRender: 'billNo' },
          width: 200,
          ellipsis: true
        },
        {
          title: '申请时间',
          align: 'center',
          dataIndex: 'createTime',
          width: 120,
          ellipsis: true
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'createBy_dictText',
          width: 80,
          ellipsis: true
        },
        {
          title: '申请人所属团队',
          align: 'center',
          dataIndex: 'costTeamId_dictText',
          width: 150,
          ellipsis: true
        },
        {
          title: '流程状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          width: 100,
          ellipsis: true
        }
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align: 'center',
        //   fixed: 'right',
        //   width: 200,
        //   scopedSlots: {
        //     filterDropdown: 'filterDropdown',
        //     filterIcon: 'filterIcon',
        //     customRender: 'action'
        //   }
        // }
      ],
      url: {
        list: '/api/erp/hr/training/erpHrTrainingApply/allList',
        delete: '/api/erp/omc/contractmanager/erpOmcContractManager/delete',
        deleteBatch: '/api/erp/omc/contractmanager/erpOmcContractManager/deleteBatch',
        exportXlsUrl: '/api/erp/omc/contractmanager/erpOmcContractManager/exportXls',
        importExcelUrl: '/api/erp/hr/training/erpHrTrainingApply/importExcel',
        queryById: '/api/erp/hr/training/erpHrTrainingApply/queryById'
      },
      dictOptions: {},
      superFieldList: [],
      disableMixinCreated: true,
      colsettings: 'ErpOmcContractManagerList2:colsettings'
    }
  },
  watch: {
    finalId: {
      handler(val) {
        if (val) {
          this.loadData()
        }
      },
      immediate: true
    }
  },
  created() {
    this.getSuperFieldList();
    this.initColumns();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() // 查询条件
      params.finalId = this.finalId
      this.loading = true
      getAction(this.url.list, params).then(res => {
        if (res.success) {
          // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result
          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
          // 判断是否当前页没有数据且不为第一页
          if (this.dataSource.length == 0 && this.ipagination.current != 1) {
            this.ipagination.current = this.ipagination.current - 1
            this.loadData(this.ipagination.current - 1);
          }
          // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    handleDetail: function (record) {
      this.$router.push({
        path: `/erp/hr/training/ErpHrTrainingApplyListDetail/${record.id}`
      })
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'handlerId', text: '经办人编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptId', text: '经办人部门ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handlerDeptCode', text: '经办人部门编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'delFlag', text: '是否已删除', dictCode: '' })
      fieldList.push({ type: 'string', value: 'htbh', text: '合同编号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'htlx', text: '合同类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jytd', text: '经营团队', dictCode: '' })
      fieldList.push({ type: 'string', value: 'htmc', text: '合同名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmmc', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'sfyz', text: '', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yzdw', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'qddw', text: '签订单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yzlx', text: '印章类型', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yyfs', text: '用印份数', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmcjr', text: '项目承接人', dictCode: '' })
      fieldList.push({ type: 'int', value: 'glskht', text: '关联收款合同', dictCode: '' })
      fieldList.push({ type: 'date', value: 'qdrq', text: '签订日期' })
      fieldList.push({ type: 'string', value: 'lxr', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'lxfs', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'int', value: 'yjgsnd', text: '业绩归属年度', dictCode: '' })
      fieldList.push({ type: 'int', value: 'skhte', text: '收款合同额', dictCode: '' })
      fieldList.push({ type: 'date', value: 'fwqx', text: '服务期限' })
      fieldList.push({ type: 'string', value: 'yf', text: '乙方', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bchtedx', text: '本次合同额大写', dictCode: '' })
      fieldList.push({ type: 'string', value: 'skhtedx', text: '收款合同额大写', dictCode: '' })
      fieldList.push({ type: 'string', value: 'skhtmc', text: '收款合同名称', dictCode: '' })
      fieldList.push({ type: 'int', value: 'bchte', text: '本次合同额', dictCode: '' })
      fieldList.push({ type: 'string', value: 'jf', text: '甲方', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xmbh', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: '' })
      fieldList.push({ type: 'int', value: 'lx', text: 'lx', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bz', text: 'bz', dictCode: '' })
      fieldList.push({ type: 'string', value: 'yjxx', text: 'yjxx', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xgfj', text: 'xgfj', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
